<?php
// -------------- CUSTOM functions ----------------
function memoryUsage($usage, $base_memory_usage) {
    $u = $usage - $base_memory_usage;
    $k = 1000000;
    $u = $u / $k;
    return $u;
} // $u = memoryUsage(memory_get_usage(), $base_memory_usage); fb($u);

function asd($var){
    ob_start();
    print_r(  $var );
    echo '<p>'.'------------------'.'</p>';
    var_dump($var);
    $a = ob_get_clean();
    file_put_contents(SITE . '/log/' . 'console.log.html' /*. rand()*/, $a);
}
function asdr($var, $metka = null){
    $num = 100;
    @$num = file_get_contents(SITE .   '/test_log_counter.txt', true);
    $num = (int)$num;
    $num++;

    ob_start();
    if(isset($metka)) echo "[$metka]";
    print_r(  $var );
    echo '<p>'.'------------------'.'</p>';
    var_dump($var);
    $a = ob_get_clean();
    file_put_contents(SITE . '/log/' . 'console.log.'.$num.'.html' , $a);
    file_put_contents(SITE . '/test_log_counter.txt' , $num);
}
function asde($source = false){
    ob_start();
    if($source  !== false) echo "<p>source:  $source</p>";
    echo "<pre>";
    debug_print_backtrace();
    echo "</pre>";
    $a = ob_get_clean();
    file_put_contents(SITE . '/log/' . 'exeption.log.'.rand().'.html' , $a);
}

function dsb($metka = 'metka'){

    $trace = debug_string_backtrace($metka);
    asdr($trace);

}

function debug_string_backtrace($metka = 'metka') {
    ob_start();

    echo "[".$metka."]\n";

    debug_print_backtrace();
    $trace = ob_get_contents();
    ob_end_clean();

    // Remove first item from backtrace as it's this function which
    // is redundant.
    $trace = preg_replace ('/^#0\s+' . __FUNCTION__ . "[^\n]*\n/", '', $trace, 1);

    // Renumber backtrace items.
    $trace = preg_replace ('/^#(\d+)/me', '\'#\' . ($1 - 1)', $trace);

    return $trace;
}

// ------------------------------